<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>权限树</title>
<link rel="stylesheet" href="${base}/static/res/plugin/ztree/css/style.css" type="text/css">
<link rel="stylesheet" href="${base}/static/res/manage/css/common.css">
<link href="${base}/static/res/manage/css/ec.css" rel="stylesheet">
<link href="${base}/static/res/manage/css/list.css" rel="stylesheet">
<style type="text/css">
body{padding:10px;min-width:250px;}
.red{margin-top:0px;}
.layerBtnDiv{padding-top:10px;text-align:center;}
.layerBtnDiv #layerCloseButton{margin-left:10px;}
</style>
<script type="text/javascript" src="${base}/static/res/plugin/jquery/jquery-1.7.2.js"></script>
<script type="text/javascript" src="${base}/static/res/plugin/ztree/js/jquery.ztree.core-3.5.min.js"></script>
<script type="text/javascript" src="${base}/static/res/plugin/ztree/js/jquery.ztree.excheck-3.5.min.js"></script>
<script type="text/javascript" src="${base}/static/res/plugin/ztree/js/jquery.ztree.exedit-3.5.min.js"></script>
<script type="text/javascript" src="${base}/static/res/plugin/validator/jquery.validate.min.js"></script>
<script type="text/javascript" src="${base}/static/res/admin/js/common.js"></script>
<script type="text/javascript" src="${base}/static/res/util/utils.js"></script>
<script type="text/javascript" src="${base}/static/res/util/areaSelUtil.js"></script>
<SCRIPT type="text/javascript">
		//树形配置
		var setting = {
            check: {
                enable: true
            },
            data: {
                key: {
                    name: "name"
                },

                simpleData: {
                    enable: true,
                    idKey: "com.project.common.web.utils.id",
                    pIdKey: "parentId",
                    rootPId: ""
                }
            },
            view: {
                selectedMulti: false
            }
        };

		//页面程序入口
        $(document).ready(function () {
            var id = $("#id").val();
            $.post("editRoleMenu.jhtml", {"id": id}, function (data) {
                if (data.success) {
                    //删除menus的url属性,这样点树节点连接才能无效
                    var jMenus = data.menus;
                    for (var i = 0; i < jMenus.length; i++) {
                        delete jMenus[i].url;
                    }
                    //初始化权限树
                    $.fn.zTree.init($("#treeDemo"), setting, data.menus);
                    var zTree = $.fn.zTree.getZTreeObj("treeDemo");
                    //复选框回显
                    var jroleMenus = data.roleMenus;
                    for(var i=0;i<jroleMenus.length;i++){
                        for(var j=0;j<jMenus.length;j++){
                            if(com.project.common.web.utils.id==com.project.common.web.utils.id){
                                var node = zTree.getNodeByParam("com.project.common.web.utils.id",com.project.common.web.utils.id,null);
                                zTree.checkNode(node, true, false);
                            }
                        }

                    }

                } else {
                    return;
                }
            });

            //确认按钮事件
            $("#layerConfirmButton").click(function(){
                var treeObj = $.fn.zTree.getZTreeObj("treeDemo"),
                        nodes = treeObj.getCheckedNodes(true),
                        treeIds = "",
                        treeNameStr = new StringBuffer();
                for (var i = 0; i < nodes.length; i++) {
                    //拼接ID
                    treeIds += com.project.common.web.utils.id;
                    if (i != nodes.length - 1) {
                        treeIds += ",";
                    }

                    //拼接name
                    if (i < 3) {
                        treeNameStr.append(nodes[i].name + "  ");
                    }
                }
                treeNameStr.append("…");
                //给父级页面赋值
                $('#menuIds', window.parent.document).val(treeIds);
                $('#menus', window.parent.document).val(treeNameStr.toString());

                //获取当前窗体索引
                var index = parent.layer.getFrameIndex(window.name);
                //执行关闭
                parent.layer.close(index);
            });

            //关闭按钮事件
            $("#layerCloseButton").click(function(){
                //获取当前窗体索引
                var index = parent.layer.getFrameIndex(window.name);
                //执行关闭
                parent.layer.close(index);
            });
	});
	</SCRIPT>
</head>
<body>	
	<form id="inputForm" action="menuToRole.jhtml" method="post">
		<input id="id" name="id" type="hidden" value="${role.id}"/>
		<ul id="treeDemo"  class="ztree ztborder "></ul>
		<div class="layerBtnDiv ">
            <input type="button" value="确认" class="red" id="layerConfirmButton" />
			<input type="button" value="关闭" class="red" id="layerCloseButton" />
		</div>
	</form>
</body>
</html>